home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / APPDICT.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  165 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.5  $
  6. //
  7. // Definition of class TAppDictionary. This class manages associations between
  8. // processes/tasks and TApplication pointers.
  9. //----------------------------------------------------------------------------
  10. #if !defined(OWL_APPDICT_H)
  11. #define OWL_APPDICT_H
  12.  
  13. #if !defined(OWL_DEFS_H)
  14. # include <owl/defs.h>
  15. #endif
  16.  
  17. #if !defined(BI_PLAT_WIN32)
  18.   inline uint GetCurrentProcessId() {return (uint)GetCurrentTask();}
  19. #endif
  20.  
  21. #if defined(BI_NAMESPACE)
  22. namespace OWL {
  23. #endif
  24.  
  25. class _OWLCLASS TApplication;
  26.  
  27. // Generic definitions/compiler options (eg. alignment) preceeding the 
  28. // definition of classes
  29. #include <services/preclass.h>
  30.  
  31. //
  32. // class TAppDictionary
  33. // ~~~~~ ~~~~~~~~~~~~~~
  34. class _OWLCLASS TAppDictionary {
  35.   public:
  36.     struct TEntry {
  37.       uint           Pid;
  38.       TApplication*  App;
  39.     };
  40.     typedef void (*TEntryIterator)(TEntry&);
  41.  
  42.   public:
  43.     TAppDictionary();
  44.    ~TAppDictionary();
  45.  
  46.     TApplication* GetApplication(uint pid = 0);  // default to current pid
  47.  
  48.     void          Add(TApplication* app, uint pid = 0);
  49.     void          Remove(TApplication* app);
  50.     void          Remove(uint pid);
  51.     void          Condemn(TApplication* app);
  52.  
  53.     bool          DeleteCondemned();
  54.     void          Iterate(TEntryIterator iter);
  55.  
  56.   private:
  57. #if defined(BI_APP_DLL) || defined(_OWLDLL) || defined(BI_PLAT_WIN32)
  58.     class TAppDictImp*  Imp;
  59. #else
  60.     TEntry        E;
  61. #endif
  62. };
  63.  
  64. // Generic definitions/compiler options (eg. alignment) following the 
  65. // definition of classes
  66. #include <services/posclass.h>
  67.  
  68. // Global exported TAppDictionary in Owl. User Component DLLs should have a
  69. // similar 'AppDictionary'.
  70. //
  71. extern TAppDictionary& _OWLFUNC OWLGetAppDictionary();
  72.  
  73. //
  74. // Global function that calls GetApplication() on owl's app-dictionary.
  75. // Used by EXEs, or DLLs statically linking Owl. Never returns 0, will make
  76. // an alias app if needed. Primarily for compatibility
  77. //
  78. TApplication* _OWLFUNC GetApplicationObject(uint pid = 0);
  79.  
  80. //
  81. // Convenient macro to define a 'AppDictionary' ref and object as needed
  82. // for use in component DLLs and EXEs
  83. //
  84. #if defined(BI_APP_DLL) && defined(_OWLDLL)
  85. # define DEFINE_APP_DICTIONARY(AppDictionary)    \
  86.   TAppDictionary  AppDictionary
  87. #else
  88. # define DEFINE_APP_DICTIONARY(AppDictionary)    \
  89.   TAppDictionary& AppDictionary = OWLGetAppDictionary()
  90. #endif
  91.  
  92. #if defined(BI_NAMESPACE)
  93. } // namespace OWL
  94. #endif
  95.     
  96. //----------------------------------------------------------------------------
  97. // inlines
  98.  
  99. //
  100. // 16bit static link exe models 
  101. //
  102. #if !defined(BI_APP_DLL) && !defined(_OWLDLL) && !defined(BI_PLAT_WIN32)
  103.  
  104. //
  105. // Constructor
  106. //
  107. inline TAppDictionary::TAppDictionary() {
  108.   E.App = 0;
  109.   E.Pid = 0;
  110. }
  111.  
  112. //
  113. // Destructor
  114. //
  115. inline TAppDictionary::~TAppDictionary() {
  116.   DeleteCondemned();
  117. }
  118.  
  119. //
  120. // GetApplication
  121. //
  122. inline TApplication* TAppDictionary::GetApplication(uint /*pid*/) {
  123.   return E.App;
  124. }
  125.  
  126. //
  127. // Add
  128. //
  129. inline void TAppDictionary::Add(TApplication* app, uint pid) {
  130.   E.App = app;
  131.   E.Pid = pid;
  132. }
  133.  
  134. //
  135. // Remove
  136. //
  137. inline void TAppDictionary::Remove(TApplication* /*app*/) {
  138.   E.App = 0;
  139. }
  140.  
  141. //
  142. // Remove
  143. //
  144. inline void TAppDictionary::Remove(uint /*pid*/) {
  145.   E.App = 0;
  146. }
  147.  
  148. //
  149. // Condemn an application
  150. //
  151. inline void TAppDictionary::Condemn(TApplication* /*app*/) {
  152.   E.Pid = 0;
  153. }
  154.  
  155. //
  156. // Iterate
  157. //
  158. inline void TAppDictionary::Iterate(TEntryIterator iter) {
  159.   (*iter)(E);
  160. }
  161.  
  162. #endif // !defined(BI_APP_DLL) && !defined(_OWLDLL) && !defined(BI_PLAT_WIN32)
  163.  
  164. #endif  // OWL_APPDICT_H
  165.